import sys

# f = [x for x in range(1,10)]
# print(f)

# f = [x + y for x in 'abcde' for y in '123456']
# print(f)

# f = [x ** 2 for x in range(1,50)]
# print(sys.getsizeof(f))
# print(f)

f = (x ** 2 for x in range(1,50))
print(sys.getsizeof(f))
# print(f)
# for val in f:
#   print(val)

# set1 = {1, 2, 3, 3, 3, 2}
# print(set1)
# print('Length =', len(set1))
# # 创建集合的构造器语法(面向对象部分会进行详细讲解)
# set2 = set(range(1, 10))
# set3 = set((1, 2, 3, 3, 2, 1))
# print(set2, set3)
# # 创建集合的推导式语法(推导式也可以用于推导集合)
# set4 = {num for num in range(1, 100) if num % 3 == 0 or num % 5 == 0}
# print(set4)

# 创建字典的字面量语法
scores = {'骆昊': 95, '白元芳': 78, '狄仁杰': 82}
# print(scores)
# # 创建字典的构造器语法
# items1 = dict(one=1,two=2,three=3,four=4)
# # 通过zip函数将两个序列压成字典
# items2 = dict(zip(['a','b','c'],'123'))
# # 创建字典的推导式语法
# items3 = {num: num ** 2 for num in range(1,10)}
# print(items1,items2,items3)

# 通过键可以获取字典中对应的值
print(scores['骆昊'])
print(scores['狄仁杰'])
# 对字典中所有键值对进行遍历
for key in scores:
    print(f'{key}: {scores[key]}')

# 更新字典中的元素
scores['白元芳'] = 65
scores['诸葛王朗'] = 71
scores.update(冷面=67, 方启鹤=85)
print(scores)
if '武则天' in scores:
    print(scores['武则天'])
print(scores.get('武则天'))
# get方法也是通过键获取对应的值但是可以设置默认值
print(scores.get('武则天', 60))

# 删除字典中的元素
print(scores.popitem())
print(scores.popitem())
print(scores.pop('骆昊', 100))
# 清空字典
scores.clear()
print(scores)
